# from datetime import time

from flask import Flask
from flask import render_template
from flask import request
import redis
import utils
from flask import jsonify
import time
app = Flask(__name__)

@app.route('/')
def index():
    return render_template("main.html")

@app.route("/time")
def get_time():
    return utils.get_time()

@app.route("/c1")
def get_c1_data():
    data = utils.get_c1_data()
    # print(jsonify({"Speed": data[0], "Price": data[1], "Order": data[2], "Rec": data[3]}))
    return jsonify({"Speed": data[0], "Price": data[1], "Order": data[2], "Rec": data[3]})

@app.route("/c2")
def get_c2_data():
    res=[]
    for tup in utils.get_c2_data():
        res.append({"name": tup[0], "value": int(tup[1])})
    # print({"data":res})
    return jsonify({"data":res})

@app.route("/l2")
def get_l2_data():
    data = utils.get_l2_data()
    type_list, value_list = [], []
    for i,j in data:
        type_list.append(i)
        value_list.append(j)
    # print({"type_list":type_list,"value_list":value_list})
    return jsonify({"type_list":type_list,"value_list":value_list})

@app.route("/l1")
def get_l1_data():
    data = utils.get_l1_data()
    type_list, value_list = [], []
    for i, j in data:
        type_list.append(i)
        value_list.append(j)
    # print({"type_list":type_list,"value_list":value_list})
    return jsonify({"type_list": type_list, "value_list": value_list})

@app.route("/r1")
def get_r1_data():
    data = utils.get_r1_data()
    type_list, value_list = [], []
    for i,j in data:
        type_list.append(i[1:10])
        value_list.append(j)
    # print({"type_list":type_list,"value_list":value_list})
    return jsonify({"type_list":type_list,"value_list":value_list})

@app.route("/r2")
def get_r2_data():
    data = utils.get_r2_data()
    type_list, value_list = [], []
    for i,j in data:
        type_list.append(i)
        value_list.append(j)
    # print({"type_list":type_list,"value_list":value_list})
    return jsonify({"type_list":type_list,"value_list":value_list})

if __name__ == '__main__':
    app.run()
